home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / dev / e / EasyPLUGINs.lha / EasyPLUGINs / source / icongad.e < prev    next >
Text File  |  1997-12-01  |  3KB  |  112 lines

  1. /*
  2.  
  3.   $VER: IconGad Plugin V1.00
  4.  
  5.   Written by:             Fabio Rotondo (fsoft@intercom.it)
  6.   
  7.   Fixed and enhanced by:  Jason Hulance (jason@fsel.com)
  8.  
  9.   This PLUGIN is part of EasyGUI PLUGINs distribution
  10.  
  11.   
  12.  
  13.   NOTE: Comments between /* */ are mine (Fabio)
  14.         Comments satrting with -> are from Jason 
  15. */
  16.  
  17. OPT OSVERSION=37
  18. OPT MODULE
  19. OPT EXPORT
  20.  
  21. MODULE  'workbench/workbench',
  22.         'exec/ports',
  23.         'icon',
  24.         'intuition/screens', 'intuition/intuition',
  25.         'gadtools', 'libraries/gadtools',
  26.         'tools/easygui', 'tools/Exceptions'
  27.  
  28.  
  29. /* 
  30.    This is our new plugin. 
  31.    Note the PRIVATE keyword: 
  32.    we don't want the user to access these fields.
  33. */
  34.     
  35. OBJECT icongad_plugin OF plugin
  36.   PRIVATE
  37.   dobj:PTR TO diskobject
  38. -> Have our own gadget (don't use dobj's gadget)
  39.   gad:PTR TO gadget
  40. ENDOBJECT
  41.  
  42. /*
  43.     This is the init proc for the plugin.
  44.     You must provide a valid icon name (full path)
  45.     without the ".info" extension (it is added automagically
  46.     by GetDiskObject() call)
  47. */
  48. PROC init(fname) OF icongad_plugin
  49.   IF (iconbase:=OpenLibrary('icon.library', 0))=NIL THEN Raise("ilib")
  50.   self.dobj := GetDiskObject(fname)
  51.   IF self.dobj = NIL THEN Raise("icon")
  52.  
  53. -> Copy the relevant parts of dobj to our gadget
  54. -> The *vital* part is the initialisation of the "activation" field to
  55. -> a known value (GACT_RELVERIFY).  That way, we know what IDCMP messages
  56. -> the gadget will generate.
  57.  
  58.   self.gad:=NEW [NIL, 0, 0, self.dobj.gadget.width, self.dobj.gadget.height,
  59.                  self.dobj.gadget.flags, GACT_RELVERIFY,
  60.                  self.dobj.gadget.gadgettype,
  61.                  self.dobj.gadget.gadgetrender,
  62.                  self.dobj.gadget.selectrender,
  63.                  NIL, 0, NIL, 0, NIL]:gadget
  64. ENDPROC
  65.  
  66. /*
  67.    We free all Alloc()ed resources.
  68.    Remeber to always END your PLUGINs before program termination.
  69. */
  70. PROC end() OF icongad_plugin
  71.   IF self.dobj THEN FreeDiskObject(self.dobj)
  72.   IF iconbase THEN CloseLibrary(iconbase)
  73.   END self.gad
  74. ENDPROC
  75.  
  76. /* The icon cannot be stretched, so it cannot be resized... */
  77. PROC will_resize() OF icongad_plugin IS FALSE
  78.  
  79.  
  80. /* We provide, as min size, the Icon size */
  81. PROC min_size(ta, fh) OF icongad_plugin IS self.gad.width, self.gad.height
  82.  
  83.  
  84. /* This is the render proc */
  85. PROC render(ta, x,y, xs, ys, win:PTR TO window) OF icongad_plugin
  86.   IF self.gad
  87.     self.gad.leftedge:=x
  88.     self.gad.topedge :=y
  89.     AddGadget(win, self.gad, NIL)
  90. -> The final argument to RefreshGList() ought to be 1, not 0
  91.     RefreshGList(self.gad, win, NIL, 1)
  92.   ENDIF
  93. ENDPROC
  94.  
  95. /* 
  96.     And here there is the clear proc 
  97.     Since we have created a standard gadget, we simply
  98.     remove it from the gadget list of the window.
  99. */
  100. PROC clear_render(win:PTR TO window) OF icongad_plugin
  101.   IF self.gad THEN IF win THEN RemoveGadget(win, self.gad)
  102. ENDPROC
  103.  
  104. PROC message_test(imsg:PTR TO intuimessage, win:PTR TO window) OF icongad_plugin
  105. -> Because we set the gadget's activation field we know we'll only get
  106. -> IDCMP_GADGETUP generated by our gadget.
  107.   IF (imsg.class=IDCMP_GADGETUP) THEN RETURN imsg.iaddress=self.gad
  108. ENDPROC FALSE
  109.  
  110. PROC message_action(a,b,c,d) OF icongad_plugin IS TRUE
  111.  
  112.